import Vue from 'vue'
import Router from 'vue-router'
import home from '@/components/home'
import commit from '@/components/commit'

Vue.use(Router)

export default new Router({
  routes: [
    {path: '/',name: 'home', component: home, meta: { requiresAuth: true }},
    // {path: '/',redirect: '/home'},
    // {path: '/home',component: Home},
    {path: '/commit',component: commit, meta: { requiresAuth: true }}
  ],
})
// function getURLParameter (name) {
//   return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null
// }
// const router = new Router({
// })
// router.beforeEach((to, from, next) => {
//   if (to.meta.requiresAuth) {
//     const token = localStorage.getItem('authToken')
//     const url = location.href
//     if (token) {
//       next()
//     } else {
//       // 重定向获取Token
//       location.href = this.$store.state.url + 'user_base/user/get_code' + '?url=' + url
//       const token = getURLParameter('token')
//       if (token) {
//         localStorage.setItem('authToken', token)
//       }
//     }
//   }
//   next()
// })